/** @format */

import {defineConfig} from 'vite';
import path from 'path';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig({
    resolve: {
        // 配置路径别名
        alias: [
            // @代替src
            {
                find: '@',
                replacement: path.resolve(__dirname, 'src'),
            },
        ],
    },
    plugins: [
        vue(),
        AutoImport({
            dts: 'types/auto-imports.d.ts', // 这里是生成的global函数文件
            imports: ['vue', 'vue-router', 'pinia'],
            include: [
                /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
                /\.vue$/,
                /\.vue\?vue/, // .vue
                /\.md$/, // .md
            ],
            resolvers: [ElementPlusResolver()],
            eslintrc: {
                // 这里先设置成true然后npm run dev 运行之后会生成 .eslintrc-auto-import.json 文件之后，在改为false
                enabled: false, // Default `false`
                filepath: './.eslintrc-auto-import.json', // 生成的文件路径
                globalsPropValue: true,
            },
        }),
        Components({
            resolvers: [ElementPlusResolver({importStyle: 'sass'})],
        }),
    ],
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: `
            @use "@/styles/element/index.scss" as *;
            @use "@/styles/var.scss" as *;
            `,
            },
        },
    },
});
